#region License

// This file is part of Grawlix.
// 
// Grawlix is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
// Grawlix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with Grawlix.  If not, see
// <http://www.gnu.org/licenses/>.

#endregion

using System.Globalization;

namespace Grawlix.Application.Gui.Messages
{
	/// <summary>
	/// Base class of keyboard input messages.
	/// </summary>
	public abstract class KeyboardInputMessage : InputMessage
	{
	}

	/// <summary>
	/// Base class of keyboard input messages.
	/// </summary>
	public abstract class KeyPressInputMessage :
		KeyboardInputMessage
	{
		/// <summary>
		/// The key that was pressed.
		/// </summary>
		private int _code;

		/// <summary>
		/// Whether the key is down.
		/// </summary>
		private bool _down;

		/// <summary>
		/// The key that was pressed.
		/// </summary>
		public int Code
		{
			get { return _code; }
			set { _code = value; }
		}

		/// <summary>
		/// Whether the key is down.
		/// </summary>
		public bool Down
		{
			get { return _down; }
			set { _down = value; }
		}

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the
		/// current <see cref="T:System.Object"/>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"/> that represents the current
		/// <see cref="T:System.Object"/>.
		/// </returns>
		public override string ToString()
		{
			return string.Format(CultureInfo.InvariantCulture,
			                     "{0}, Code: {1}, Down: {2}",
			                     base.ToString(), _code, _down);
		}
	}

	/// <summary>
	/// Notification of a key being released.
	/// </summary>
	public class KeyUpInputMessage : KeyPressInputMessage
	{
		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="KeyUpInputMessage"/> class.
		/// </summary>
		public KeyUpInputMessage()
		{
			Down = false;
		}
	}

	/// <summary>
	/// Notification of a key being pressed.
	/// </summary>
	public class KeyDownInputMessage : KeyPressInputMessage
	{
		/// <summary>
		/// Initializes a new instance of the 
		/// <see cref="KeyDownInputMessage"/> class.
		/// </summary>
		public KeyDownInputMessage()
		{
			Down = true;
		}
	}

	/// <summary>
	/// Notification of character input.
	/// </summary>
	public class CharacterInputMessage : KeyboardInputMessage
	{
		/// <summary>
		/// The received input character.
		/// </summary>
		private char _character;

		/// <summary>
		/// The received input character.
		/// </summary>
		public char Character
		{
			get { return _character; }
			set { _character = value; }
		}

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the
		/// current <see cref="T:System.Object"/>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"/> that represents the current
		/// <see cref="T:System.Object"/>.
		/// </returns>
		public override string ToString()
		{
			return string.Format(CultureInfo.InvariantCulture,
			                     "Character: {0}", _character);
		}
	}
}